package cn.chinaflame.pagodas.Result;

import cn.chinaflame.pagodas.enums.CodeEnum;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class Result<T> {
    //错误码
    private String code;
    //错误信息
    private String msg;
    //具体的内容
    private T data;

    public Result() {
    }

    public Result(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(T data) {
        this.code = CodeEnum.SUCCESS.getCode();
        this.msg = CodeEnum.SUCCESS.getMsg();
        this.data = data;
    }

    public static <T> Result<T> create(String code, String msg) {
        return new Result<>(code, msg);
    }

    public static <T> Result<T> create(T data) {
        return new Result<>(data);
    }

    public static <T> ResultPage<T> createPage(String code, String msg) {
        return new ResultPage<>(code, msg);
    }

    public static <T> ResultPage<T> createPage(T data) {
        return new ResultPage<>(data);
    }

    public static <T> ResultPage<T> createPage(T data, Integer pageIndex, Integer pageSize, Long pageCount) {
        return new ResultPage<>(data, pageIndex, pageSize, pageCount);
    }

    public static <T> ResultPage<T> createPage(T data, Long pageCount) {
        return new ResultPage<>(data, pageCount);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        // TODO Auto-generated method stub
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

}
